package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingPlanController
 * @Author mzx
 * @Date 2024-07-08
 */
@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 护理计划分页查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/plan/search")
    @ApiOperation("分页查询护理计划列表")
    public ResponseResult<PageResponse<NursingPlanVo>> getBypage(
            @ApiParam(value = "护理计划名称") String name,
            @ApiParam(value = "护理计划状态") Integer status,
            @ApiParam(value = "页码（默认为1）")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页大小（默认为10")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
         PageResponse<NursingPlanVo> bypage = nursingPlanService.getBypage(name, status, pageNum, pageSize);
        return ResponseResult.success(bypage);
    }

    /**
     * 新增护理计划
     *
     * @param nursingPlanDto
     * @return
     */
    @PostMapping("/plan")
    @ApiOperation("新增护理计划")
    public ResponseResult add(@ApiParam("新增护理计划") @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.add(nursingPlanDto);
        return success();


    }

    /**
     * 根据id查询护理计划
     *
     * @param id
     * @return
     */
    @GetMapping("/plan/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanVo> findById(@ApiParam("护理计划id") @PathVariable Integer id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.findById(id);
        return ResponseResult.success(nursingPlanVo);

    }



    /**
     * 修改护理计划
     *
     * @param nursingPlanDto
     * @return
     */
    @PutMapping("/plan/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult update(@ApiParam("修改护理计划") @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.updateById(nursingPlanDto);
        return success();
    }

    /**
     * 修改护理计划状态
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理计划状态")
    public ResponseResult updateStatus(
            @ApiParam("护理计划的id") @PathVariable Integer id,
            @ApiParam("状态，0：禁用，1：启用") @PathVariable Integer status
    ) {
        nursingPlanService.updateStatus(id, status);
        return ResponseResult.success();

    }

    /**
     * 查询所有护理计划
     * @return
     */

    @GetMapping("/plan")
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> findAll() {
       List <NursingPlanVo> nursingPlanVo = nursingPlanService.findAll();
        return ResponseResult.success(nursingPlanVo);
    }

    //删除
    @DeleteMapping("/plan/{id}")
    @ApiOperation(value = "护理计划删除",notes = "护理计划删除")
    public ResponseResult deleteId(@PathVariable Integer id){
        nursingPlanService.deleteId(id);
        return ResponseResult.success();
    }
}
